package com.dyzx.hbb.aliyun.sms.utils;

import lombok.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 阿里云 SMS 短信模板.
 *
 * @author cn-src
 */
@Builder(builderClassName = "Builder", toBuilder = true)
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor


public class SmsTemplate {
    private String signName;
    private String templateCode;
    private Map<String, String> templateParam;
    private List<String> phoneNumbers;

    public static class Builder {
        /**
         * -- GETTER --
         *  获取构建的短信模板参数.
         *
         * @return 短信模板参数映射
         */
        @Getter
        private final Map<String, String> templateParam = new ConcurrentHashMap<>(8); // 默认初始容量为8，适合大多数场景

        /**
         * 添加短信模板参数.
         *
         * @param key   参数键，不能为空
         * @param value 参数值，不能为空
         * @return this
         * @throws IllegalArgumentException 如果 key 或 value 为空
         */
        public Builder addTemplateParam(final String key, final String value) {
            if (key == null || key.isEmpty()) {
                throw new IllegalArgumentException("Parameter 'key' cannot be null or empty");
            }
            if (value == null || value.isEmpty()) {
                throw new IllegalArgumentException("Parameter 'value' cannot be null or empty");
            }

            templateParam.put(key, value);
            return this;
        }

    }
}
